package 接口.练习;

interface IUSB{
    void openDevice();
    void closeDevice();

}
class Mouse implements IUSB{

    @Override
    public void openDevice() {
        System.out.println("打开鼠标");
    }

    @Override
    public void closeDevice() {
        System.out.println("关闭鼠标");
    }
    static void click(){
        System.out.println("点击鼠标");
    }
}
class KeyBoard implements IUSB{

    @Override
    public void openDevice() {
        System.out.println("打开键盘");
    }

    @Override
    public void closeDevice() {
        System.out.println("关闭键盘");
    }
    static void input(){
        System.out.println("键盘输入");
    }
}
class Computer{
    void openOn(){
        System.out.println("打开电脑");
    }
    void closeOn(){
        System.out.println("关闭电脑");
    }
    void useDevice(IUSB usb){
        usb.openDevice();
        if(usb instanceof Mouse){
            Mouse.click();
        }else if(usb instanceof KeyBoard){
            KeyBoard.input();
        }
        usb.closeDevice();
    }
}
public class Interface_Text_1 {
    public static void main(String[] args) {
        Computer computer = new Computer();
        //打开电脑
        computer.openOn();
        System.out.println("========");
        //使用电脑各个部件
        Mouse mouse =new Mouse();
        computer.useDevice(mouse);

        KeyBoard keyBoard = new KeyBoard();
        computer.useDevice(keyBoard);
        //关闭电脑
        System.out.println("============");
        computer.closeOn();
    }
}
//打开电脑
//========
//打开鼠标
//点击鼠标
//关闭鼠标
//打开键盘
//键盘输入
//关闭键盘
//============
//关闭电脑
